package com.zjsru.oneday202208;

/**
 * @Author: likew
 * @Date: 2022/9/9
 * 文件夹操作日志搜集器
 * "../" ：移动到当前文件夹的父文件夹。如果已经在主文件夹下，则 继续停留在当前文件夹 。
 * "./" ：继续停留在当前文件夹。
 * "x/" ：移动到名为 x 的子文件夹中。题目数据 保证总是存在文件夹 x 。
 *
 * 输入：logs = ["d1/","d2/","../","d21/","./"]
 * 输出：2
 * 解释：执行 "../" 操作变更文件夹 2 次，即可回到主文件夹
 *
 * 输入：logs = ["d1/","d2/","./","d3/","../","d31/"]
 * 输出：3
 *
 */
public class MinOperations {
    public int minOperations(String[] logs) {
        int ans = 0;
        for (String s:logs) {
            if(s.equals("../")){
                ans = Math.max(0,ans - 1 );
            }else if(!s.equals("./")){
                ans++;
            }
        }
        return ans;
    }
    
    public static void main(String[] args) {
        MinOperations minOperations = new MinOperations();
        String[] logs = new String[]{"./","wz4/","../","mj2/","../","../","ik0/","il7/"};
        System.out.println(minOperations.minOperations(logs));
    }
}
